package com.iswust.visual.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iswust.visual.mapper.SiteMonitoringDataMapper;
import com.iswust.visual.model.SiteMonitoringData;
import com.iswust.visual.model.vo.DateTimeVo;
import com.iswust.visual.model.vo.RadarVo;
import com.iswust.visual.service.SiteMonitoringDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author swust
 * @since 2023-02-17
 */
@Service
public class SiteMonitoringDataServiceImpl extends ServiceImpl<SiteMonitoringDataMapper, SiteMonitoringData> implements SiteMonitoringDataService {
    @Autowired
    private SiteMonitoringDataMapper siteMonitoringDataMapper;

    @Override
    public List<RadarVo> getRadarData(DateTimeVo dateTimeVo) {
        final List<SiteMonitoringData> siteDataByDay = siteMonitoringDataMapper.getSiteDataByDay(dateTimeVo);
        List<RadarVo> radarVos = new ArrayList<>();
        for (SiteMonitoringData siteMonitoringData : siteDataByDay) {
            final RadarVo radarVo = new RadarVo();
            List<Double> values =new ArrayList<>();
            radarVo.setName(siteMonitoringData.getSite());
            //['SO2', 'NO2', 'CO', 'O3', 'PM10', 'PM2.5']
            values.add(siteMonitoringData.getSo2());
            values.add(siteMonitoringData.getNo2());
            values.add(siteMonitoringData.getCo());
            values.add(siteMonitoringData.getO3());
            values.add(siteMonitoringData.getPm10());
            values.add(siteMonitoringData.getPm25());
            radarVo.setValue(values);
            radarVos.add(radarVo);
        }
        return  radarVos;
    }
}
